from django.db import models
from django.contrib.auth.models import User


class CustomUser(User):

    def __str__(self):
        return self.username + ' - ' + self.first_name


class Clazz(models.Model):
    clazz_name = models.CharField(null=False, verbose_name='班级名', max_length=30)

    class Meta:
        verbose_name = '班级'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.clazz_name


class Student(models.Model):
    user = models.ForeignKey(CustomUser, verbose_name='用户', on_delete=models.DO_NOTHING)
    clazz = models.ForeignKey(Clazz, on_delete=models.CASCADE, verbose_name='班级')
    checkIn = models.ManyToManyField('sign.CheckInTask', verbose_name='参与的打卡', through='sign.StudentCheckIn')

    class Meta:
        verbose_name = '学生'
        verbose_name_plural = verbose_name
        unique_together = ('user', 'clazz')

    def __str__(self):
        return self.user.username + ' - ' + str(self.clazz) + ' - ' + self.user.first_name


class Manager(models.Model):
    user = models.ForeignKey(CustomUser, on_delete=models.DO_NOTHING, verbose_name='用户')
    clazzs = models.ManyToManyField(Clazz, verbose_name='管理班级')

    class Meta:
        verbose_name = '管理员'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.username


# class MangeClazz(models.Model):
#     clazz = models.ForeignKey(Clazz, on_delete=models.DO_NOTHING)
#     manager = models.ForeignKey(Manager, on_delete=models.DO_NOTHING)
#
#     class Meta:
#         verbose_name = '管理班级'
#         verbose_name_plural = verbose_name
#
#     def __str__(self):
#         return self.clazz + ' - ' + self.manager







